load("@bazel_gomock//:gomock.bzl", "gomock")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "scexec",
    srcs = [
        "dependencies.go",
        "exec_backfill.go",
        "exec_deferred_mutation.go",
        "exec_immediate_mutation.go",
        "exec_mutation.go",
        "exec_validation.go",
        "executor.go",
        "gc_jobs.go",
        "testing_knobs.go",
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scexec",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/config/zonepb",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobsprotectedts",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/protectedts/ptpb",
        "//pkg/roachpb",
        "//pkg/security/username",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/nstree",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/schemachanger/scerrors",
        "//pkg/sql/schemachanger/scexec/scmutationexec",
        "//pkg/sql/schemachanger/scop",
        "//pkg/sql/schemachanger/scpb",
        "//pkg/sql/schemachanger/scplan",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sessiondata",
        "//pkg/util/ctxgroup",
        "//pkg/util/hlc",
        "//pkg/util/intsets",
        "//pkg/util/timeutil",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
    ],
)

go_test(
    name = "scexec_test",
    size = "medium",
    srcs = [
        "exec_backfill_test.go",
        "executor_external_test.go",
        "main_test.go",
        ":mock_scexec",  # keep
    ],
    deps = [
        ":scexec",
        "//pkg/base",
        "//pkg/clusterversion",
        "//pkg/config/zonepb",  # keep
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/roachpb",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog",
        # catalogkeys is required to build the generated output of mock_scexec
        "//pkg/sql/catalog/catalogkeys",  # keep
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/catalog/lease",
        "//pkg/sql/catalog/nstree",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/isql",
        "//pkg/sql/parser",
        "//pkg/sql/schemachanger/scbuild",
        "//pkg/sql/schemachanger/scdecomp",
        "//pkg/sql/schemachanger/scdeps",
        "//pkg/sql/schemachanger/scdeps/sctestdeps",
        "//pkg/sql/schemachanger/scdeps/sctestutils",
        # scmutationexec is required to build the generated output of mock_scexec
        "//pkg/sql/schemachanger/scexec/scmutationexec",  # keep
        "//pkg/sql/schemachanger/scop",
        "//pkg/sql/schemachanger/scpb",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/catid",  # keep
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/types",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/sqlutils",
        "//pkg/util/hlc",
        "//pkg/util/iterutil",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/mon",
        "//pkg/util/randutil",
        "//pkg/util/timeutil",
        "@com_github_golang_mock//gomock",
        "@com_github_stretchr_testify//require",
    ],
)

gomock(
    name = "mock_scexec",
    out = "mocks_generated_test.go",
    imports = {
        "scexec": "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scexec",
    },
    interfaces = [
        "Catalog",
        "Dependencies",
        "Backfiller",
        "Merger",
        "BackfillerTracker",
        "IndexSpanSplitter",
        "PeriodicProgressFlusher",
    ],
    library = ":scexec",
    package = "scexec_test",
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)
